package producerconsumer;

public class Consumer implements Runnable {
    private final Buffer buffer;

    public Consumer(Buffer buffer) {
        this.buffer = buffer;
    }

    public void run() {
        try {
            while (true) {
                String i = buffer.take();
                System.out.print(i + " ");
                System.out.flush();
                Thread.sleep((long) (Math.random() * 1000.0));
            }
        } catch (InterruptedException e) {
            // allow thread to die
        }
    }
}
